﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ValidationLibrary;

namespace WebFormModelBinderEntities
{
    public class MyFirstEntity : IValidatable<MyFirstEntity>
    {
        public string Name { get; set; }
        public int Rating { get; set; }
        public bool IsActive { get; set; }
        public bool IsDeleted { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }

        public ModelValidator<MyFirstEntity> ModelValidator
        {
            get { return new MyFirstEntityValidator(); }
        }
    }

    public class MyFirstEntityValidator : ModelValidator<MyFirstEntity>
    {
        public MyFirstEntityValidator()
        {
            Rule(x => x.StartDate < new DateTime(2010, 06, 01))
                .Message("Must be before 01-06-2010");
            Rule(x => x.EndDate > x.StartDate)
                .Message("Must end after it starts");
            Rule(x => x.IsActive || x.IsDeleted)
                .Message("Must be either active or deleted");
            Rule(x => !string.IsNullOrEmpty(x.Name))
                .Message("Name must not be empty.");
        }
    }
}
